package sharetime.util;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

import org.dom4j.Document;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;

public class Dom4JUtil {
	public static void saveDocumentTo(Document doc, String folder,
			String fileName) throws IOException {
		OutputFormat format = OutputFormat.createPrettyPrint();
		File file = new File(folder, fileName);
		if (!file.exists())
			file.createNewFile();
		OutputStreamWriter writeOut = new OutputStreamWriter(
				new FileOutputStream(file), "UTF-8");
		XMLWriter writer = new XMLWriter(writeOut, format);
		writer.write(doc);
		writer.close();
	}
}
